package merisis.traitspace;

import java.util.logging.Logger;

import merisis.traitspace.History;
import merisis.util.BitUtil;

import org.apache.solr.util.OpenBitSet;


public class TraitTestUtil {

	public static OpenBitSet[] bsg(OpenBitSet... bs) {
		return bs;
	}

	public static OpenBitSet bs(long... categories) {

		OpenBitSet s = new OpenBitSet();

		if (categories == null)
			return s;

		for (int i = 0; i < categories.length; i++) {
			s.set(categories[i]);
		}

		return s;
	}

	public static boolean eq(long[] a, long[] b) {

		OpenBitSet abs = bs(a);
		OpenBitSet bbs = bs(b);

		return OpenBitSet.xorCount(abs, bbs) == 0;
	}

	public static long[][] aa(long[]... e) {

		long[][] r = new long[e.length][];

		for (int i = 0; i < e.length; i++) {
			r[i] = e[i];
		}

		return r;
	}

	public static long[] ay(long... e) {

		long[] r = new long[e.length];

		for (int i = 0; i < e.length; i++) {
			r[i] = e[i];
		}

		return r;
	}

	public static void dumpHistory(History ht, Logger logger, int from, int to) {

		StringBuilder sb = new StringBuilder();
		sb.append("\n");
		for (long i = from; i <= to; i++) {

			OpenBitSet bs = new OpenBitSet();
			long[] list = ht.next(i);
			if (list == null)
				continue;

			sb.append(String.format("%02d: ", i));
			BitUtil.format(sb, BitUtil.bitsetOrArray(bs, list), ",");
			sb.append("\n");
		}
		logger.info(sb.toString());
	}
}
